package com.kolaxy.social.govern.reviewer.service;

import com.kolaxy.social.govern.reviewer.ReviewerService;
import com.kolaxy.social.govern.reviewer.dao.ReviewerTaskStatusDao;
import com.kolaxy.social.govern.reviewer.domain.ReviewerTaskStatus;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * @Description TODO
 * @Author zrj
 * @Date 2020/9/1 19:31
 * @Version 1.0
 */
@Service(version = "1.0.0",
        interfaceClass = ReviewerService.class,
        cluster = "failfast",
        loadbalance = "roundrobin")
public class ReviewerImpl implements ReviewerService {

    @Autowired
    private ReviewerTaskStatusDao reviewerTaskStatusDao;

    public List<Long> selectReivewers(Long reportTaskId) {
        System.out.println("selectReivewers--------------");
        List<Long> reviewer = Arrays.asList(1L, 2L, 3L, 4L, 5L);

        for (Long reviewId : reviewer) {
            ReviewerTaskStatus status = new ReviewerTaskStatus();
            status.setReportTaskId(reportTaskId);
            status.setReviewerId(reviewId);
            status.setStatus(ReviewerTaskStatus.PROCESSING);
            reviewerTaskStatusDao.add(status);
        }
        return reviewer;
    }

    public void finishVote(Long reviewerId, Long reportTaskId) {
        ReviewerTaskStatus status = new ReviewerTaskStatus();
        status.setReviewerId(reviewerId);
        status.setReportTaskId(reportTaskId);
        status.setStatus(ReviewerTaskStatus.FINISHED);
        reviewerTaskStatusDao.update(status);
    }
}
